<template>
  <view>
    <picker mode="selector" :range="list"  @change="onSelect">
      <view class="picker">
        当前分区： {{selected}}
      </view>
    </picker>
	<kingScan ref="childRef" scanMode="scanCode" :fid="fid" :selected="selected"></kingScan>
  </view>
</template>

<script> 
import kingScan from '@/uni_modules/king-scan/king-scan.vue';
export default {
	components: { kingScan },
  data() {
    return {
      items: [],
      list: [1,2],
      selected: '' ,// 初始选中值
	  fid:'',
    };
  },
  onShow() {
      this.load(); // 在页面再次显示时更新list数据
	  this.selected = ''
	  this.$refs.childRef.init();
  },
  methods: {
    load() {
      var _this = this;
      uni.getStorage({
        key: 'items',
        success: function (res) {
          console.log('从本地读取的数据为：', res.data);
          _this.items = JSON.parse(res.data); 
		  _this.list = _this.items.map(e=>e.value); 
        }
      });
    },
    onSelect(e) {
	  console.log(e);	
      this.selected = this.list[e.detail.value];
	  this.fid = this.items.filter(e=>e.value == this.selected)[0].id
	  this.$refs.childRef.init();
    }
  }
};
</script>

<style>
.picker {
  padding: 10px;
  background-color: #fff; 
  color: #000;
}
</style>